﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace RR {
    public class PlayerCtrl : MonoBehaviour
    {
        public bool isLeft;
        //角色旋转的速度
        public float rotateSpees;

        //判断角色位置的bool
        private bool m_isRight;
        private bool n_isRight;

        //分别代表左右两个球的素材
        public Texture[] m_playerTextuer;
        public Texture[] n_playerTextuer;
        // Use this for initialization
        void Start()
        {

            InitTexture(Global.lastValue);

            m_isRight = true;
            n_isRight = true;
        }

        public void InitTexture(int value)
        {
            if (!isLeft)
            {
                this.gameObject.GetComponent<Renderer>().material.mainTexture = m_playerTextuer[value];
            }
            else
            {
                this.gameObject.GetComponent<Renderer>().material.mainTexture = n_playerTextuer[value];
            }
        }

        public void M_OnPosChange()
        {
            if (m_isRight)
            {
                transform.position += Vector3.left * -2.5f;
                m_isRight = false;
            }
            else
            {
                transform.position += Vector3.left * 2.5f;
                m_isRight = true;
            }
        }

        public void N_OnPosChange()
        {
            if (n_isRight)
            {
                transform.position += Vector3.left * -2.5f;
                n_isRight = false;
            }
            else
            {
                transform.position += Vector3.left * 2.5f;
                n_isRight = true;
            }
        }

        // Update is called once per frame
        void Update()
        {
            if (!Global.isGameOver)
            {
                transform.Rotate(Vector3.left * rotateSpees * Time.deltaTime);
            }
        }
    }

}
